define(["jquery", "easy-admin", "vue"], function ($, ea, Vue) {
    let form = layui.form;
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'weixin.express_order/index',
        add_url: 'weixin.express_order/add',
        edit_url: 'weixin.express_order/edit',
        delete_url: 'weixin.express_order/delete',
        export_url: 'weixin.express_order/export',
        modify_url: 'weixin.express_order/modify',
    };
    var Controller = {
        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'delete', 'export'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id'},
                    {field: 'order_id', title: '订单号', minWidth: 180},

                    {field: 'wechat.avatarUrl', title: '用户头像', templet: ea.table.image, search: false, width: 180},
                    {field: 'wechat.nickName', title: '用户昵称', search: false, width: 100},
                    {
                        field: 'pay_type',
                        title: '支付方式',
                        width: 100,
                        selectList: {1: '快递次数', 2: '订单免费', 3: '现金支付', 4: '次数不足 组合支付'}
                    },
                    {
                        field: 'pay_status',
                        title: '支付状态',
                        width: 100,
                        selectList: {1: '已支付', 2: '未支付'}
                    },
                    {field: 'shop.title', title: '店铺', width: 180},
                    {field: 'realname', title: '联系人', width: 180},
                    {field: 'mobile', title: '电话', width: 180},
                    {field: 'address', title: '地址', width: 180},
                    {field: 'order_number', title: '订单总数', width: 180},
                    {field: 'pay_number', title: '支付订单数', width: 180},
                    {field: 'unit_price', title: '单价', width: 180},
                    {field: 'express_number', title: '减少快递次数', width: 180},
                    {field: 'price', title: '实付金额', width: 180},
                    {field: 'create_time', title: '创建时间', width: 180},
                    {field: 'status', search: 'select', selectList: {"0": "未送", "1": "已送"}, title: '状态'},
                    {
                        width: 200, title: '操作', templet: ea.table.tool, operat: [[{
                            class: 'layui-btn layui-btn-xs layui-btn-success',
                            method: 'open',
                            text: '查看详情',
                            auth: 'success',
                            url: init.edit_url,
                            extend: 'data-full="true"',
                        }], 'delete']
                    },
                ]],

            });

            ea.listen();
        },
        edit: function () {
            $(".btn_status").on('click', function () {
                let id = $(this).data("id");
                let type = $(this).data('type');
                layer.confirm('您确定收货吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.post("/admin/weixin.expressOrder/saveStatus", {
                        id: id,
                        type: type
                    }).then(res => {
                        if (res.code == 1) {
                            layer.msg(res.msg, {icon: 6, shade: 0.1}, function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                                parent.layer.close(index); //再执行关闭
                            })
                        } else {
                            layer.msg(res.msg, {icon: 5, shade: 0.5});
                            return;
                        }
                    })
                });
                return false;
            })
            ea.listen();
        }
    };
    return Controller;
});